import React, {useMemo, useState} from 'react';

const UseMemoCount = () => {

    const [count, setCount] = useState(0)

    // 缓存值，只有第一次和依赖的值变化才执行，类似计算属性
    const memoText = useMemo(() => {
        console.log("memoText 执行了");
        return 'time：' + new Date().getTime()
    }, []);

    return (
        <div>
            <p>{memoText}={count}</p>
            <button onClick={() => setCount(count => count + 1)}>+</button>
        </div>
    );
};

export default UseMemoCount;
